<template>
	<view class="page-body">
		<!-- <view class="p20 bg-white smll">
			<view class="calendar_box flex_bd" @click="show=true">
				<view class="text fs26">时间：{{calendarText}}
					<u-icon class="ml10" name="arrow-down-fill" size="20"></u-icon>
				</view>
			</view>
			<view class="fr">
				<view class="selectText fs26" @click="selectshow=true">{{selectText}}<u-icon class="ml10" name="arrow-down-fill" size="20"></u-icon></view>
				<u-action-sheet :list="rewardTypeList" :cancel-btn="false" @click="selectRewardType" v-model="selectshow"></u-action-sheet>
			</view>
		</view>
		<u-calendar v-model="show" ref="calendar" @change="changeCalendar" :mode="mode" :start-text="startText" :end-text="endText"
		 :btn-type="btnType" :mask-close-able="false">
		</u-calendar> -->
		<view class="navbar mt10">
			<view v-for="(item, index) in navList" :key="index" class="nav-item" :class="{current1: tabCurrentIndex === index}"
			 @click="tabClick(index)">
				{{item.text}}
			</view>
		</view>
		<swiper :current="tabCurrentIndex" class="swiper-box bg-white" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem,tabIndex) in navList" :key="tabIndex">
				<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
					<!-- 空白页 -->
					<empty v-if="tabItem.loaded === true && tabItem.list.length === 0"></empty>
					<!-- 列表 -->
					<view v-for="(item,index) in tabItem.list" :key="index" class="item b-tottom">
						<view class="header_title">
							<image :src="item.userinfo.headimgurl?config.baseUrl+item.userinfo.headimgurl:'/pagesB/static/channel/images/order_type02.png'" mode=""></image>
							<text> {{item.userinfo.nick_name?item.userinfo.nick_name:'平台'}}</text>	
							<text :class="[item.status=='已返'?'fr fs18 color_yifan':item.status=='待返'?'fr fs18 color_daifan':'fr fs18 color_cannel']">{{item.status}}</text>
						</view>
						<view class="shouyitype">收益类型：{{item.reward_name}} 
						</view>
						<view class="shouyitype">创建时间：{{item.add_time}}
						</view>
						<!-- <view class="mt10 color-94">
							<text >创建时间{{item.add_time}}</text>
						</view> -->
						<!-- <view class="mt10 color-94">
							<text>分佣层级：{{item.to_proxy_name}}</text>
							<text class="fr" v-if="item.from_uid > 0">分佣会员：{{item.to_uid}}</text>
						</view> -->
						<view class="img_content">
							<image src="../../../static/public/images/baozhengjin.png" class="fl"></image>
							<view class="info mt10">
								<view class="reward_info">{{item.reward_info}}</view>
								<!-- <view class="all_money">￥{{item.reward_money}}</view> -->
							</view>
						</view>
						<view class="">
							
							<text class="fr shouyitext">收益：<text style="color: #F06C50;">￥{{item.reward_money}}</text></text>
						</view>
						<view class="action-box p20">
							<button v-if="item.buttom == 2" class="action-btn green" @click="disposeLog(item.id,index,3)">确认打款</button>
							<button v-if="item.buttom == 1" class="action-btn green" @click="disposeLog(item.id,index,2)">确认收款</button>
						</view>
					</view>
					<uni-load-more :status="tabItem.loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import empty from "@/components/empty";
	export default {
		components: {
			uniLoadMore,
			empty
		},
		data() {
			return {
				selectText:'全部奖励',
				rewardTypeList:[
					{
						text: '全部奖励',
						id:'all'
					}
				],
				selectshow: false,
				calendarText: '',
				show: false,
				mode: 'range',
				result: "请选择日期",
				startText: '开始',
				endText: '结束',
				btnType: 'primary',
				startDate: '',
				endDate: '',
				tabCurrentIndex: 0,
				param: {
					calendar: '',
					rewardType:'all',
					state: 0,
					p: 0
				},
				navList: [{
						state: 'all',
						text: '全部',
						loadingType: 'more',
						list: [],
						p: 0
					},
					{
						state: '1',
						text: '待返',
						loadingType: 'more',
						list: [],
						p: 0
					},
					{
						state: '2',
						text: '已返',
						loadingType: 'more',
						list: [],
						p: 0
					},
					{
						state: '9',
						text: '取消',
						loadingType: 'more',
						list: [],
						p: 0
					}
				],
			}
		},
		onLoad() {
			this.loadData()
		},
		onShow() {
		},
		onReady() {},
		methods: {
			changeCalendar(e) {
				this.calendarText = e.startDate + "~" + e.endDate;
				this.param.calendar = this.calendarText;
				this.searchText = this.calendarText;
				this.loadData('change');
			},
			selectRewardType(index){
				var sel = this.rewardTypeList[index];
				this.selectText = sel.text;
				this.param.rewardType = sel.id;
				this.loadData('change');
			},
			//获取订单列表
			loadData(source) {
				//这里是将订单挂载到tab列表下
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				if (source === 'change'){
					navItem.list = [];
					navItem.p = 0;
					navItem.loadingType = 'more';
				}
				if (navItem.loadingType == 'nomore' || navItem.loadingType === 'loading') {
					return;
				}
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				
				navItem.p++;
				this.param.state = navItem.state;
				this.param.p = navItem.p;
				navItem.loadingType = 'loading';
				this.$u.post('channel/api.wallet/getRewardLog', this.param).then(res => {
					navItem.list = navItem.list.concat(res.data.list);
					//loaded新字段用于表示数据加载完毕，如果为空可以显示空白页
					this.$set(navItem, 'loaded', true);
					//判断是否还有下一页，有是more  没有是nomore
					navItem.loadingType = navItem.p == res.data.page_count ? 'nomore' : 'more';
					if (this.calendarText == '') {
						this.calendarText = res.data.startDate + '~' + res.data.endDate;
						res.data.rewardList.forEach(item=>{
							this.rewardTypeList.push(item);
						})
					}
				})
			},
			
			//swiper 切换
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData();
			},
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			},
			// 订单操作
			disposeLog(id,_index,_status){

				let navItem = this.navList[this.tabCurrentIndex];
				this.$u.post('channel/api.Wallet/disposeRewardLog', {id:id,status:_status}).then(res => {
					navItem.list[_index].buttom = 0;
					if(_status == 3){
						navItem.list[_index].status = '待确定';
					} else {
						navItem.list[_index].status = '已返';
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	@import "~@/pagesB/static/channel/css/wallet.scss";

	.line_box {
		.text {
			margin-top: 10rpx;
			color: $font-color-light;
		}
	}

	.swiper-box {
		height: calc(100%);
		.list-scroll-content {
			position: relative;
			height: 100%;
			.item {
				padding: 20rpx;
				font-size: 30rpx;
					
				.info{
					display: block;
					font-size: 28rpx;
					color: $font-color-light;
				}
				.money {
					font-size: 30rpx;
					font-weight: 700;
					color: $font-color-base;
				}
			}
		}
	}
	.current1{
		color: #C39F4F;
		font-weight: 600;
	}
	.navbar .nav-item.current1:after {
	    content: '';
	    position: absolute;
	    display: inline-block;
	    left: 50%;
	    bottom: 0;
	    width: 60%;
	    -webkit-transform: translateX(-50%);
	    transform: translateX(-50%);
	    border-bottom: 2px solid;
	    border-color: #C39F4F;
	    background-color: #C39F4F;
	}
	.b-tottom {
	    border-top: 15px solid #F2F2F2;
		border-bottom: 0.5px solid #F2F2F2;
	}
	.shouyitext{
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #666666;
	}
	.color_yifan{
		color: #333333;
	}
	.color_daifan{
		color: #C39F4F;
	}
	.color_cannel{
		color: #999999 	;
	}
	.header_title{
		height: 80rpx;
		line-height: 80rpx;
	}
	.header_title image{
		height: 70rpx;
		width: 70rpx;
		border-radius: 50%;
		margin-right: 10rpx;
	}
	.shouyitype{
		margin-top: 10rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
	}
	.img_content{
		height: 160rpx;
	}
	.img_content image{
		height: 150rpx;
		width: 150rpx;
	}
	.img_content view{
		position: relative;
		left: 10rpx;
	}
	.img_content .all_money{
		color: #333333;
		font-size: 34rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
	}
	.img_content .reward_info{
		font-size: 28rpx;
		height: 100rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #86869C;
	}
</style>
